package one.stand.dto;

import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * @author cjr
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageRequest {
    private Integer pageSize = 10;
    private Integer pageNum = 1;

    public void setPageInit(Integer pageNum, Integer pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public void limit(Integer size) {
        this.pageNum = 1;
        this.pageSize = size;
    }

    public void setAll() {
        this.pageNum = -1;
    }

    public void startPage() {
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize) && pageNum > 0 && pageSize > 0) {
            PageHelper.startPage(pageNum, pageSize);
        }
    }
}
